package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import java.util.Optional;

import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserInfoHelper;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;

/**
 * @ClassName : IsSignAnotherSupplier
 * @Description : 是否总部直签客户 CON3015
 * @Author : xie.zhengjun
 * @Date : 2021/3/14 17:11
 */
@Service
@UserAttrSupplier(attrField = LocalKeyConsts.IS_LEADER_SIGN_NEW)
public class IsSignAnotherSupplier extends AbstractUserAttrSupplier{
    @Override
    public String getValue() {
        String isSignVal = UserInfoHelper
            .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.IS_LEADER_SIGN);
        if (KiteStringUtils.isEmpty(isSignVal)) {
            isSignVal = UserInfoHelper
                .getValueFromUserItemInfoMap(userInfoContext.getUserItemInfoMap(), LocalKeyConsts.IS_LEADER_SIGN_NEW);
        }
        return isSignVal;
    }

    @Override
    public String getValueDesc() {
        String isSignVal = getValue();
        return Optional.ofNullable(AttrValueCache.getAttrValue("2020110806", isSignVal))
            .map(AttrValue::getAttrValueName).orElse(isSignVal);
    }
}
